package dataTypes;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.persistence.MappedSuperclass;
import java.util.Date;

import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

/* 
 * The activeDeals DB will contain sighed users with all the deals they sighed to.
 * Should have: user name/unique id, deal id, business id, how many the user purchased, 
 * boolean used, 
 * This is where you update when a user sighs to a deal. A user can appear 
 * more then one time but only once per deal
 * ==> minimal key is user+deal id 
 * 
 * This allows businesses to retrieve all users who sighed to a deal as well as to 
 * manage the deal as it goes and also save deals history for future use. 
 * It also allows to retrieve a specific user deals history.
 *  
 */

@PersistenceCapable(detachable="true")
public class activeUserDeals {

	
	

	public activeUserDeals(String googleName, int numPurchased,deal d,
			boolean didUse) {
		super();
		this.googleName = googleName;
		this.numPurchased = numPurchased;
		this.didUse = didUse;
		this.active = true;
		this.deal=d;
		this.couponcode=0;
		this.timeTaken = new Date();
		this.timeTaken.setTime(timeTaken.getTime() + 10800000);
		this.setTimeUsed(null);

	}

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Key key;
	

	
	@Persistent
	private String googleName;


	@Persistent
	private boolean active;
	

	@Persistent
	private int numPurchased; 

	@Persistent
	private boolean didUse;
	
	@Persistent (defaultFetchGroup="true")
	private deal deal;
	
	@Persistent
	private long couponcode;
	
	@Persistent
	private Date timeTaken;

	@Persistent
	private Date timeUsed;
	
	
	public Key getKey() {
		return key;
	}
	
	public void generateCouponCode(){
		if (this.couponcode==0){
			this.couponcode=Math.abs(this.key.hashCode());
		}
			
	}
	
	public long getcouponcode(){
		return this.couponcode;
	}
	
	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}
	

	public void setKey(Key key) {
		this.key = key;
	}

	public String getUser() {
		return this.googleName;
	}

	public void setUser(String googleName) {
		this.googleName = googleName;
	}

	public int getNumPurchased() {
		return numPurchased;
	}

	public void setNumPurchased(int numPurchased) {
		this.numPurchased = numPurchased;
	}

	public boolean isDidUse() {
		return didUse;
	}

	public void setDidUse(boolean didUse) {
		this.didUse = didUse;
	}

	public void setDeal(deal deal) {
		this.deal = deal;
	}

	public deal getDeal() {
		return deal;
	}

	public void setTimeUsed(Date timeUsed) {
		this.timeUsed = timeUsed;
	}

	public Date getTimeUsed() {
		return timeUsed;
	}

	public void setTimeTaken(Date timeTaken) {
		timeTaken.setTime(timeTaken.getTime()+10800000);
		this.timeTaken = timeTaken;
	}

	public Date getTimeTaken() {
		return timeTaken;
	}

	
}



